﻿using System;
using System.Collections.Generic;
using System.Text;

/// <summary>
/// 当托管类型和非托管类型在内存结构上完全对应时，两边都可以直接使用时，而不用作任何封装转换，这个类型就是Blittable的
/// From MSDN
/// https://msdn.microsoft.com/en-us/library/75dwhxf7(v=vs.110).aspx
/// 
/// 说文解字时间
/// blit == BLock Image Transfer = BL + I + T
/// blittable = blit t able
/// blittable类型，即可以直接内存复制(位块传送)的类型
/// </summary>
namespace spec_unsafe.Blittable
{
    struct DirtyStruct//is dirty
    {
        public int a;
        public int b;
        public string abc; //string is dirty (ref type,point)
    }
    struct DirtyStruct2//is dirty
    {
        public DirtyStruct a;//use dirty
        public int b;
    }
    struct CleanStruct
    {
        public int a;
        public int b;
        public bool c;
    }
    struct CleanStruct2
    {
        public int a;
        public int b;
        unsafe fixed char abc[8];
    }
    struct CleanStruct3
    {
        public CleanStruct a;
        public int b;
    }
    class blittable
    {
        static void TestBlittable()
        {
            unsafe
            {
                //编译失败，size实验
                //DirtyStruct* d1 = stackalloc DirtyStruct[10];
                //DirtyStruct2* d2 = stackalloc DirtyStruct2[10];

                CleanStruct* c1 = stackalloc CleanStruct[10];
                CleanStruct2* c2 = stackalloc CleanStruct2[10];
            }
        }
    }
}
